﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace sieuthi.Threelayer.DAL
{
    public class UserDAL_Control:VO.ketnoi
    {
        public List<VO.loginVO> _User_xem()
        {
            List<VO.loginVO> list = new List<VO.loginVO>();
            using (SqlCommand dbCmd = new SqlCommand("User_xem", GetConnection()))
            {
                VO.loginVO obj = new VO.loginVO();
                dbCmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.loginIDataReader(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        public bool _User_them(VO.loginVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("User_them", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                    dbCmd.Parameters.Add(new SqlParameter("@Password", data.Password));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool _User_sua(VO.loginVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("User_sua", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@Name", data.Name));
                dbCmd.Parameters.Add(new SqlParameter("@Password", data.Password));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool _User_xoa(string Id)
        {
            using (SqlCommand dbCmd = new SqlCommand("User_xoa", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@mahd", Id));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
       
    }
}
